package com.lry.crawlers.comic.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.lry.crawlers.comic.entity.ComicUpdate;
import com.lry.crawlers.comic.mapper.ComicUpdateMapper;
import com.lry.crawlers.comic.service.ComicUpdateService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class ComicUpdateServiceImpl implements ComicUpdateService {
    @Autowired
    ComicUpdateMapper comicUpdateMapper;

    @Override
    public int setComicUpdate(ComicUpdate comicUpdate) {
        return comicUpdateMapper.insert(comicUpdate);
    }

    @Override
    public List<ComicUpdate> getComicUpdates() {
        return comicUpdateMapper.selectList(null);
    }

    @Override
    public int setComicUpdateUp(ComicUpdate comicUpdate) {
        QueryWrapper wrapper = new QueryWrapper();
        wrapper.eq("comic_id", comicUpdate.getComicId());
        return comicUpdateMapper.update(comicUpdate,wrapper);
    }

    @Override
    public ComicUpdate getComicUpdate(String comicId) {
        QueryWrapper wrapper = new QueryWrapper();
        wrapper.eq("comic_id",comicId);
        return comicUpdateMapper.selectOne(wrapper);
    }

    @Override
    public List<ComicUpdate> getComicUpdateByCVId(Integer id) {
        QueryWrapper wrapper = new QueryWrapper();
        wrapper.eq("comic_variable_id",id);
        List<ComicUpdate> list = comicUpdateMapper.selectList(wrapper);
        if(list.size()!=0)
            return list;
        else
            return null;
    }

    @Override
    public void setComicUpdateAddNum(String comicId) {
        comicUpdateMapper.setComicUpdateAddNum(comicId);
    }

}
